package main

/**
 * @author: SuZhiXiaoWei
 * @DateTime: 2022/2/21 10:34
 **/
//区块链管理区块
type BlockChain struct {
	Blocks []*Block
}

/**
创建区块链
*/
func NewChain(data []byte) *BlockChain {
	chain := BlockChain{}
	chain.Blocks = []*Block{}
	//创建一个创世区块存入BlockChain
	genesis := GenesisBlock(data)
	chain.Blocks = append(chain.Blocks, genesis)
	return &chain
}
/**
把区块添加到区块链中
 */
func (bc *BlockChain)AddBlockChain(data []byte){
	//创建区块
	 newBlock := NewBlock(data,bc.Blocks[len(bc.Blocks)-1].Hash)
	//将区块添加到区块链中
	bc.Blocks = append(bc.Blocks,newBlock)

}